<template>
  <base-breadcrumb>
    <searchData
      :search-data="searchArr"
      @search="search"
    />
    <a-card :bordered="false">
      <list-table
        ref="table"
        :columns="columns"
        :statistics-config="{ use: true, statistics}"
        :request="loadData"
        :export-config="{use:true,select:'物资设备采购策划选中',all:'物资设备采购策划全部'}"
      >
        <template
          slot="prefix"
        >
          <a-button
            v-btnPermission="'mm_002_add_01'"
            type="primary"
            icon="plus"
            @click="handleEdit(null,1)"
          >
            新增
          </a-button>
        </template>
        <span
          slot="index"
          slot-scope="text, record, index"
        >{{ index + 1 }}</span>
        <template
          slot="auditStatusStr"
          slot-scope="text, record"
        >
          <list-status
            :status="record.auditStatus"
            :text="text"
          />
        </template>
        <template
          slot="operation"
          slot-scope="text, record"
        >
          <MoreButton>
            <a @click="handleEdit(record, 3)">查看</a>
            <template v-if="record.auditStatus === 'DRAFT' || record.auditStatus === 'REJECTED'">
              <a @click="handleEdit(record, 2)">编辑</a>
              <a @click="handleDel(record.id)">删除</a>
            </template>
            <approval-button
              :id="record.id"
              :status="record.auditStatus"
              v-if="record.auditStatus === 'PAST' || record.auditStatus === 'SUBMITTED' || record.auditStatus === 'REJECTED' || record.auditStatus === 'REVOKEIN' || record.auditStatus === 'REVOKE' || record.auditStatus === 'ABOLISH' || record.auditStatus === '1' || record.auditStatus === '3' || record.auditStatus === 'COMMIT'|| record.auditStatus === '2' "
            />
          </MoreButton>
        </template>
      </list-table>
    </a-card>
  </base-breadcrumb>
</template>

<script>
import {
    equipmentPurchaseList,
    equipmentPurchaseDel,
    findListCount,
    print
} from '@/api/material/materialMasterPlan/equipmentPurchasePlan'
import SelectSubCompany from '@/components/Select/SelectSubCompany'
import SelectProject from '@/components/Select/SelectProject'

export default {
	name:'a'+Date.now(),
  // name:'a'+Date.now(),
  name:'EquipmentPurchasePlanIndex',
    data() {
        return {
            columns: [
                {
                    title: '序号',
                    dataIndex: 'index',
                    scopedSlots: { customRender: 'index' },
                    width: 70
                }, {
                    title: '所属分公司',
                    dataIndex: 'branchCompany',
                    width: 150
                },
                {
                    title: '物资设备采购策划编码',
                    dataIndex: 'purchaseCode',
                    width: 180
                },
                {
                    title: '项目名称',
                    dataIndex: 'projectName',
                    width: 120
                },
                {
                    title: '编号',
                    dataIndex: 'code',
                    width: 120
                },
                {
                    title: '创建人',
                    dataIndex: 'creatorName',
                    width: 150
                },
                {
                    title: '创建时间',
                    dataIndex: 'createTime',
                    width: 160
                },
                {
                    title: '状态',
                    dataIndex: 'auditStatusStr',
                    width: this.STATUS_WIDTH,
                    scopedSlots: { customRender: 'auditStatusStr' }
                },
                {
                    title: '操作',
                    dataIndex: 'operation',
                    width: 200,
                    fixed: 'right',
                    scopedSlots: { customRender: 'operation' }
                }
            ],
            searchArr: [
                // 搜索框
                {
                    name: '所属分公司',
                    valueKey: 'branchCompanyId',
                    type: SelectSubCompany
                },
                // {
                //     name: '项目名称',
                //     type: SelectProject,
                //     valueKey: 'projectId'
                // },
                // 搜索框
                {
                    name: '采购策划编码',
                    value: 'purchaseCode',
                    type: 'input'
                },
                {
                    name: '编号',
                    value: 'materialPurchaseNumber',
                    type: 'input'
                },
                {
                    name: '创建人',
                    value: 'createName',
                    type: 'input'
                },
                {
                    name: '创建时间',
                    value: 'create',
                    type: 'timeRangeFormat'
                },
                {
                    name: '状态',
                    type: 'select',
                    value: 'auditStatus',
                    data: this.STATUS
                }
            ],
            queryParam: {},
            loadData: (params) => {
                let searchData = Object.assign(params, this.queryParam)
                findListCount(searchData).then(res => {
                    if (res.code === this.SUCCESS_CODE) this.statistics = res.data
                })
                return equipmentPurchaseList(searchData)
            },
            statistics: {},
            chooseId: null
        }
    },

    methods: {
        search(val) {
            this.queryParam = val || {}
            this.$refs.table.getData(null, true)
        },
        handleAdd() {
            this.$router.push({
                path: '/material/equipmentPurchasePlanAdd',
                query: {
                    type: true
                }
            })
        },
        handleEdit(record, state) {
            this.$router.push({
                path: '/material/equipmentPurchasePlanAdd',
                query: {
                    id: record && record.id || '',
                    state: state
                }
            })
        },
        handleDel(id) {
            this.delList(equipmentPurchaseDel, this.search, { ids: [id] })

        }
    }
}
</script>
